/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.spring5.SpringTemplateEngine;
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;
import org.thymeleaf.templatemode.TemplateMode;

/**
 * <p>Project: springmvc2021 - ThymeleafConfig
 * <p>Powered by webrx On 2021-11-05 17:40:43
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
@Configuration
public class ThymeleafConfig {
    @Bean
    public SpringResourceTemplateResolver templateResolver() {
        var t = new SpringResourceTemplateResolver();
        t.setPrefix("classpath:/templates/");
        t.setSuffix(".html");
        t.setCharacterEncoding("utf-8");
        t.setTemplateMode(TemplateMode.HTML);
        t.setCacheable(false);
        return t;
    }

    @Bean
    public SpringTemplateEngine templateEngine() {
        SpringTemplateEngine templateEngine = new SpringTemplateEngine();
        templateEngine.setTemplateResolver(templateResolver());
        templateEngine.setEnableSpringELCompiler(true);
        return templateEngine;
    }

    @Bean
    public ThymeleafViewResolver viewResolver() {
        ThymeleafViewResolver view = new ThymeleafViewResolver();
        view.setCharacterEncoding("utf-8");
        view.setOrder(1);
        view.setTemplateEngine(templateEngine());
        return view;
    }
}
